﻿@{
    ViewBag.Title = "Index";
}
<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
    <title>用户管理中心</title>
        <link href="~/themes/css/easyui.css"  rel="stylesheet" />
    <link href="~/themes/css/icon.css" rel="stylesheet" />
    <link href="~/themes/css/Site.css" rel="stylesheet" />

    <script type="text/javascript" src="~/scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/scripts/jquery.easyui.min.js"></script>   
    <script type="text/javascript" src="~/scripts/easyui-lang-zh_CN.js"></script>   
    @*修改时间格式的Js文件*@
    <script src="~/scripts/datapattern2.js"></script>
    <script src="~/scripts/ckeditor/ckeditor.js"></script>

    <script type="text/javascript">
        $(function () {
            //初始化弹出窗体
            initTable();
        });
        //初始化表格 
        function initTable(queryData) {
            $('#test').datagrid({
                title: '留言管理',
                iconCls: 'icon-save',
                height: 600,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                url: '/Company/GetAllNote',
                sortName: 'ID',
                sortOrder: 'asc',
                //striped:true,
                border: true,
                remoteSort: false,
                idField: 'ID',
                pagination: true,
                rownumbers: true,
                queryParams: queryData,
                columns: [[
                    { field: 'ck', checkbox: true },
					{ field: 'ID', title: 'ID', width: 50, sortable: true },
					{ field: 'Topic', title: '留言主题', width: 100, sortable: true },
                    { field: 'Position', title: "身 份", width: 100, sortable: true, },
                    { field: 'People', title: "留言者", width: 100, sortable: true, },
                    { field: 'Phone', title: "电 话", width: 100, sortable: true, },
                    //{ field: 'Website', title: "网 址", width: 125, sortable: true, },
                    { field: 'Mail', title: "邮 箱", width: 125, sortable: true, },
                    { field: 'Words', title: "留言内容", width: 200, sortable: true, },
                    { field: 'Type', title: "状 态", width: 100, sortable: true, },
                    {
                        field: 'Action1', title: '操  作', width: 75, align: 'center',
                        formatter: function (value, row, index) {
                        var l = '<a href="#" onclick="lookrow(this)">查看</a> ';
                        return l;
                         }
                     },
                    {
                        field: 'Action2', title: '操  作', width: 75, align: 'center',
                        formatter: function (value, row, index) {
                        var r = '<a href="#" onclick="replyrow(this)">回复</a>';;
                        return r;
                        }
                    },
                    {
                        field: 'Action3', title: '操  作', width: 75, align: 'center',
                        formatter: function (value, row, index) {
                        var d = '<a href="#" onclick="deleterow(this)">删除</a>';
                        return d;
                        }
                    }
                ]],
                toolbar: [{
                    id: 'btnadd',
                    text: '查看留言',
                    iconCls: 'icon-add',
                    handler: function () {
                        //实现弹出查看留言的层
                        LookNoteByClick();
                    }
                }, '-', {
                    id: 'btncut',
                    text: '回复留言',
                    iconCls: 'icon-cut',
                    handler: function () {
                        //实现弹出回复留言层
                        ReplyByClick();
                    }
                }, '-', {
                    id: 'btnsave',
                    text: '删除留言',
                    iconCls: 'icon-remove',
                    handler: function () {
                        //实现删除留言
                        DeleteByClick();
                    }
                }]
            });
        }

        function deleterow(target) {
                    //$('#tt').datagrid('deleteRow', getRowIndex(target));
                        DeleteByClick();
        }

        function lookrow(target) {
            LookNoteByClick();
        }

        function replyrow(target) {
            ReplyByClick();
        }
       
        //弹出查看留言界面
        function LookNoteByClick()
        {
            var lookid = $("#test").datagrid("getSelected");
            var LookID = $("#test").datagrid("getSelections");
            if (LookID.length == 1||lookid.length==1) {
                location.href = "/Company/Note?ID=" + LookID[0].ID;
            }
            else {
                $.messager.alert("友情提示","每次只能查看一条留言，您选怎了<font color='red' size='6'>"+LookID.length+"</font>条留言。");
            }
            
        }

        //弹出回复界面
        function ReplyByClick()
        {
            var lookid = $("#test").datagrid("getSelected");
            var LookID = $("#test").datagrid("getSelections");
            if (LookID.length == 1||lookid.length==1) {
                //弹出回复留言的对话框
                $('#ReplyNoteDialog').dialog('open').dialog('setTitle', '回复留言');
            }
            else {
                $.messager.alert("友情提示", "每次只能回复一条留言，您选怎了<font color='red' size='6'>" + LookID.length + "</font>条留言。");
            }
        }

        //实现删除留言
        function DeleteByClick()
        {
            var lookid = $("#test").datagrid("getSelected");
            var deleteID = $("#test").datagrid("getSelections");
            if (deleteID.length >= 1||lookid.length==1) {
                var ids = "";   //1,2,3,4
                for (var i = 0; i < deleteID.length; i++) {
                    ids += deleteID[i].ID + ",";
                }
                ids = ids.substring(0, ids.length - 1);

                //遍历出删除文章的信息
                var Notelist = "";
                for (var i = 0; i < deleteID.length; i++) {
                    Notelist += deleteID[i].Topic + ",";
                }
                Notelist = Notelist.substring(0, Notelist.length - 1);
                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + Notelist + "</font>留言吗？", function (DeleteNoteInfo) {
                    if (DeleteNoteInfo) {
                        $.post("/Company/DeleteNoteInfo", { deleteID: ids, Notelist: Notelist }, function (data) {
                            if (data == "OK") {
                                $.messager.alert("友情提示", "删除成功");
                                $("#test").datagrid("reload");
                                $("#test").datagrid("clearSelections");
                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "请您选择要删除的留言");
            }
        }

        </script>
</head>
<body>
    <div>
        <table id="test"></table>
    </div>
     @*----------------回复留言----------------------*@
    <div id="ReplyNoteDialog" class="easyui-dialog" style="width:360px;height:310px;padding:10px 20px"
			closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="UpdateUserInfo" method="post" novalidate="novalidate">
            <table>
                <tr>
                    <td><label>回复留言</label></td>
                </tr>
                <tr>
                    <td><textarea id="reply" style="width:200px;height:150px" name="reply" ></textarea></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align:center; padding-top:10px">
                        <a href="javascript:void(0)" class="easyui-linkbutton" id="btnReply1" iconcls="icon-ok" >回复</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#ReplyNoteDialog').dialog('close')">关闭</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>